using System.Linq;
using System;
using System.Windows.Input;

namespace MvcMusicStore.BI.Client.Commands
{
  public abstract class CommandBase : CommandCore, ICommand
  {
    #region ICommand Members

    public Boolean CanExecute(Object parameter)
    {
      return CanExecute() && !IsExecuting;
    }

    public void Execute(Object parameter)
    {
      try
      {
        if (!CanExecute(parameter)) return;

        if (OnExecutingCore())
        {
          Execute();
        }
      }
      catch (Exception exception)
      {
        OnExecutedCore(CommandExecutionResult.FromException(exception));
      }
    }

    #endregion

    protected abstract bool CanExecute();

    protected abstract void Execute();
  }
}
